/**
 * 定义冻结表格行列的工具类模块
 */
(function(window, angular, undefined){

	var Module = angular.module('water.common.dateTimePicker',['water.common.dateUtil']);
	
	/**
	 * 日期时间选择控件
	 */
	Module.directive("dateTimePicker", function($dateUtil) {
		return {
		    restrict: "A",     
		    require : "ngModel",
		    scope: {              
		    	 model:"=ngModel"
		    }, 
		    link:function($scope, elm, attrs, controller){
		    	$.datetimepicker.setLocale('ch');
		    	elm.datetimepicker({
		    		format:'Y-m-d H:i:00',
		    		step: 5,
		    		onChangeDateTime:function(a,b,c,d){
		    			safeApply($scope,(function(){
		    					$scope.model = $dateUtil.formatDate(a);
                         	})
                         );
		    		}
		    	});
		    	
		    	function safeApply(scope, fn) {  
		    	    (scope.$$phase || scope.$root.$$phase) ? fn() : scope.$apply(fn);  
		    	}  
		    }
		 } 
	});
	/**
	 * 日期时间选择控件(只显示到小时)
	 */
	Module.directive("dateHourTimePicker", function($dateUtil) {
		return {
		    restrict: "A",     
		    require : "ngModel",
		    scope: {              
		    	 model:"=ngModel"
		    }, 
		    link:function($scope, elm, attrs, controller){
		    	$.datetimepicker.setLocale('ch');
		    	elm.datetimepicker({
		    		dateFormat:'yy-mm-dd',
		    		timeFormat: 'HH',//格式化时间
		    		onChangeDateTime:function(a,b,c,d){
		    			safeApply($scope,(function(){
		    					$scope.model = $dateUtil.formatDate(a);
                         	})
                         );
		    		}
		    	});
		    	
		    	function safeApply(scope, fn) {  
		    	    (scope.$$phase || scope.$root.$$phase) ? fn() : scope.$apply(fn);  
		    	}  
		    }
		 } 
	});
	
}(window, angular));